package com.edu.exam.entity.assessment.plan;

import com.edu.exam.enums.ExamForm;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 考试科目实体类
 * 所属模块：B-05 考核计划管理模块
 * 对应数据库表：exam_subject
 *
 * <p>考试计划中的科目实体，记录具体科目的考试安排信息。
 * 每个科目对应一门具体的考试，包含考试时间、地点、形式、
 * 时长等详细信息。是考试计划的具体执行单元。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "exam_subject")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExamSubject {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 考试计划ID
     */
    @Column(name = "plan_id", nullable = false)
    private Long planId;

    /**
     * 科目编码
     */
    @Column(name = "subject_code", length = 20, nullable = false)
    private String subjectCode;

    /**
     * 科目名称
     */
    @Column(name = "subject_name", length = 100, nullable = false)
    private String subjectName;

    /**
     * 考试日期
     */
    @Column(name = "exam_date", nullable = false)
    private LocalDate examDate;

    /**
     * 开始时间
     */
    @Column(name = "start_time", nullable = false)
    private LocalTime startTime;

    /**
     * 结束时间
     */
    @Column(name = "end_time", nullable = false)
    private LocalTime endTime;

    /**
     * 考试时长（分钟）
     */
    @Column(name = "duration", nullable = false)
    private Integer duration;

    /**
     * 考试形式
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "exam_form", length = 20, nullable = false)
    private ExamForm examForm;

    /**
     * 考试地点
     */
    @Column(name = "exam_location", length = 200)
    private String examLocation;

    /**
     * 监考人数
     */
    @Column(name = "invigilator_count", nullable = false)
    private Integer invigilatorCount;

    /**
     * 科目顺序
     */
    @Column(name = "subject_order", nullable = false)
    private Integer subjectOrder;

    /**
     * 科目描述
     */
    @Column(name = "subject_description", length = 500)
    private String subjectDescription;

    /**
     * 课程ID
     */
    @Column(name = "course_id")
    private Long courseId;

    /**
     * 课程名称
     */
    @Column(name = "course_name", length = 200)
    private String courseName;

    /**
     * 教学班ID
     */
    @Column(name = "teaching_class_id")
    private Long teachingClassId;

    /**
     * 教学班名称
     */
    @Column(name = "teaching_class_name", length = 200)
    private String teachingClassName;

    /**
     * 应考人数
     */
    @Column(name = "expected_students")
    private Integer expectedStudents;

    /**
     * 实考人数
     */
    @Column(name = "actual_students")
    private Integer actualStudents;

    /**
     * 满分
     */
    @Column(name = "full_score")
    private Integer fullScore;

    /**
     * 及格分
     */
    @Column(name = "passing_score")
    private Integer passingScore;

    /**
     * 考试要求（JSON格式）
     */
    @Column(name = "exam_requirements", columnDefinition = "TEXT")
    private String examRequirements;

    /**
     * 考试材料（JSON格式）
     */
    @Column(name = "exam_materials", columnDefinition = "TEXT")
    private String examMaterials;

    /**
     * 特殊安排
     */
    @Column(name = "special_arrangements", length = 1000)
    private String specialArrangements;

    // ===== 审计字段 =====

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 版本号
     */
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;
}
